/**
 * Created by Administrator on 15-6-11.
 */
var Seat = RichBase.extend({
	statics : {
		api : "call/jh_show.php"
	},
	EVENTS : {
		"blur" : {
			".createInp" :"onCreateInpBlur"
		},
		"focus" : {
			".createInp" : "onCreateInpFocus"
		},
		"click" : {
			"#createSeatBtn" : "onCreateBtnClick",
			"#saveBtn" : "onSubmit"
		}
	},
	init : function(opt){
		this.stage = new opt.Stage({
			container : $("#stageWrap"),
			stageUl : $("#stageUlW"),
			stageWidth : opt.stageWidth,
			offsetX : opt.offsetX
		});
		this.rowInp = $("#createSeatRowInp");
		this.colInp = $("#createSeatColInp");
		var venueid = this.venueid = $("#venueIdHidInp").val();
		this.getVenueMeg(venueid);
	},
	getVenueMeg : function(venueid){
		if(!venueid) return false;
		var that = this;
		var api = this.statics.api;
		PFT.Ajax({
			url : api,
			type : "GET",
			dataType : "json",
			data : {
				action : "get_venue_seat",
				venue_id : venueid
			},
			loading : function(){},
			removeLoading : function(){},
			timeout : function(){},
			serverError : function(){}
		},function(res){
			that.stage.setOrignData(res);
			var venue_name = res.venue_name || "";
			var layout = res.layout; //布局方式
			var areas = res.areas;
			var col = res.col_num || 20;
			var row = res.row_num || 8;
			$("#venuename").text(venue_name);
			that.rowInp.val(row);
			that.colInp.val(col);
			$("#odd_first_optUl").find(".option .layoutType_"+layout).trigger("click");
			//构建分区
			that.stage.buildAreaList(areas);
			var editMode = false;
			for(var i in areas){
				var seats = areas[i]["seats"];
				if(seats.length){
					editMode = true;
					break;
				}
			}
			that.stage.buildStage();
		})
	},
	onSubmit : function(that,e){
		var btn = $(e.currentTarget);
		if(btn.hasClass("loading")) return false;
		that.stage.submit();
	},
	onCreateBtnClick : function(that,e){
		e.preventDefault();
		var row = Number($("#createSeatRowInp").val());
		var col = Number($("#createSeatColInp").val());
		var radio = $("#odd_first_optUl").find("input[type=radio]:checked");
		var layout = radio.hasClass("layoutType_1") ? 1 : 2;
		that.stage.create({
			row : row,
			col : col,
			layout : layout
		})
	},
	onCreateInpBlur : function(that,e){
		var tarInp = $(e.currentTarget);
		var val = tarInp.val();
		if(!PFT_GLOBAL.U.isPositiveNum(val)) tarInp.val(tarInp.attr("data-orign"));
	},
	onCreateInpFocus : function(that,e){
		var tarInp = $(e.currentTarget);
		tarInp.attr("data-orign",tarInp.val());
	}
});


var seat = new Seat({
	container:$("#createSeatWrap"),
	Stage : Stage,
	stageWidth : 700,
	offsetX : 0
});




